package org.project.product.android.pfe.fanta.adapter;

import java.util.List;

import org.project.product.android.pfe.fanta.domain.Category;
import org.project.product.android.pfe.fanta.domain.Product;
import org.project.product.android.pfe.fanta.domain.User;
import org.project.product.android.pfe.fanta.view.CategoryItemView;
import org.project.product.android.pfe.fanta.view.ProductItemView;
import org.project.product.android.pfe.fanta.view.UserItemView;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class UserListAdapter extends BaseAdapter {

	private List<User> users;

	public UserListAdapter(List<User> users) {
		super();
		this.users = users;
	}

	@Override
	public int getCount() {
		return users.size();
	}

	@Override
	public Object getItem(int position) {
		return users.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		User user = users.get(position);
		if (convertView != null && convertView instanceof CategoryItemView) {
			UserItemView itemView = (UserItemView) convertView;
			itemView.reuse(user);
			return itemView;
		}
		return new UserItemView(parent.getContext(), user);
	}

}
